package com.example.kotlinlanguage

import java.math.BigInteger

/**
 * 版权：卓灿教育集团 版权所有
 * author :赵航
 * @e-mail: zhaohangcn@gmail.com
 * time：2020/12/28
 * describe ：
 */
fun main() {
//    var num:BigInteger = BigInteger("100")
//    println(fact(num))
    var result = 0
    var num = 1000000
    println(ollAdd(num,result))
}

fun fact(num: BigInteger): BigInteger {
    if (num == BigInteger.ONE) {
        return BigInteger.ONE
    } else {
        return num * fact(num - BigInteger.ONE)
    }
}

tailrec fun ollAdd(num: Int, result: Int): Int {
    if (num == 0) {
        return result
    } else {
        return ollAdd(num - 1, num + result)
    }
}